<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="cts" value="${pageContext.request.contextPath}"/>
<html xmlns="http://www.w3.org/1999/xhtml">
<!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
body {
	background: #F5F5F5;
	text-align: center;
}
table {
	text-align: center;
	margin: 0px auto;
}
th {
	background-color: silver;
}
</style>
<script type="text/javascript" src="/js/ajax.js"></script>
<script type="text/javascript">
	function changePnum(pid){
		var iptObj = document.getElementById(pid);
		var oldPnumObj = document.getElementById("old_"+pid);
		var reg =/^[1-9][0-9]*$/;
		if(!reg.test(iptObj.value)){
			alert("请输入正整数！");
			return;
		}
		var xmlHttp = ajaxFunction();
		xmlHttp.open("POST", "${cts}updatePnum.action", true);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");	//通知服务器发送的数据是请求参数
		xmlHttp.send("pid="+pid+"&newPnum="+iptObj.value);
		xmlHttp.onreadystatechange = function(){
			if(xmlHttp.readyState == 4){
				//判断服务器是否处理成功
				if(xmlHttp.status == 200){
					//接受响应数据
					var result = xmlHttp.responseText;
					if(result == "true"){ //数量修改成功
						oldPnumObj.value = iptObj.value;
						alert("商品数量修改失败！");
					}else{
						alert("商品数量修改成功！");
					}
				}
			}
		}
	}
function deleteProd(pid){
	if(window.confirm("您确定删除？")){
		window.location.href = "${cts}deleteProd.action?id="+pid;
	}
}
</script>
</head>
<body>
	<br/>
	<h2><a href="/back/prod_add.jsp">添加商品</a></h2>
	<hr>
	<table bordercolor="black" border="1" width="95%" cellspacing="0px" cellpadding="5px">
		<tr>
			<th>全选<input type="checkbox" > </th>
			<th>商品图片</th>
			<th>商品id</th>
			<th>商品名称</th>
			<th>商品种类</th>
			<th>商品单价</th>
			<th>库存数量</th>
			<th>描述信息</th>
			<th nowrap="nowrap">&nbsp;&nbsp;操&nbsp;&nbsp;&nbsp;&nbsp;作&nbsp;&nbsp;</th>
		</tr>
	<c:forEach items="${prodList}" var="prod" varStatus="stat">
		
			<tr  <c:if test="${stat.count%2==1}">class="row1"</c:if>
			<c:if test="${stat.count%2==0}">class="row2"</c:if>>
				<td><input type="checkbox" >  </td>
				<td><img width="120px" height="120px" src="${prod.imgurl}"/></td>
				<td>${prod.id}</td>
				<td>${prod.name }</td>
				<td>${prod.category}</td>
				<td>${prod.price}</td>
				<td>
				<input type="hidden" id="hd_${prod.id }" value="${prod.pnum }"/>
				<input type="text" id="${prod.id}" value="${prod.pnum }" 
					style="width: 50px" onblur="changePnum('${prod.id}')"/></td>
				<td>${prod.description }</td>
				<td><a href="javascript:void(0)" onclick="deleteProd('${prod.id}')">删除</a>
				<a href="#"></a></td>
			</tr>
	</c:forEach>
	</table>
</body>
</html>
